/*
 * \brief  Root client interface
 * \author Norman Feske
 * \date   2006-05-11
 */

/*
 * Copyright (C) 2006-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__ROOT__CLIENT_H_
#define _INCLUDE__ROOT__CLIENT_H_

#include <root/capability.h>
#include <base/ipc.h>
#include <base/lock.h>

namespace Genode {

	class Root_client : public Root
	{
		private:

			Msgbuf<256> _snd_msg, _rcv_msg;
			Ipc_client  _ipc_client;
			Lock        _lock;

		public:

			/**
			 * Constructor
			 */
			Root_client(Root_capability root)
			: _ipc_client(root, &_snd_msg, &_rcv_msg) { }


			/********************
			 ** Root interface **
			 ********************/

			Session_capability session(const char *args)
			{
				Lock::Guard lock_guard(_lock);
				Session_capability session;
				_ipc_client << SESSION << Buffer(args) << IPC_CALL >> session;
				return session;
			}

			void close(Session_capability session)
			{
				Lock::Guard lock_guard(_lock);
				_ipc_client << CLOSE << session << IPC_CALL;
			}
	};
}

#endif /* _INCLUDE__ROOT__CLIENT_H_ */
